<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Proxy 与 Reflect</title>
</head>
<body>
  <script>
   const user = {
     name: 'tom',
     age: 12
   }

  // 创建一个代理对象
  const userProxy = new Proxy(user, {
    // 读取属性
    get (target, property, receiver) {
      console.log('拦截到了读取属性')
      return Reflect.get(target, property, receiver)
    },
    // 修改属性 / 添加属性
    set(target, property, value, receiver) {
      console.log('拦截到了设置或添加属性')
      return Reflect.set(target, property, value, receiver)
    },
    // 删除属性
    deleteProperty(target, property) {
      console.log('拦截到删除属性')
      return Reflect.deleteProperty(target, property)
    }
  })

  // 通过代理对象操作数据
  // 读取属性
  // console.log(userProxy.name)

  // 修改已有属性
  // userProxy.name = 'atguigu'
  // 添加新属性
  // userProxy.sex = '女'
  // 删除属性
  delete userProxy.name

  console.log(user)

  
   
  </script>
</body>
</html>